#include <iostream>
#include <string>
#include <dlfcn.h>
#include <string.h>
#include <ncurses.h>
#include "StrFormat.h"

extern "C" {

void Test1()
{
    initscr();
    raw();
    noecho();
    curs_set(0);
 
    const char* c = "Hello, World!";
    const char* d = "Hello, World!!!";
 
    mvprintw(LINES/2,(COLS-strlen(c))/2,c);
    refresh();
 
    getch();
    endwin();
}

void Test2()
{
    std::cout << "test2\n";
}

WINDOW *CreateNewWin(int height, int width, int starty, int startx)
{
    WINDOW *local_win;
    local_win = newwin(height, width, starty, startx);
    box(local_win, 0 , 0);
    /* 0, 0 是字符默认的行列起始位置 */
    wrefresh(local_win);
    /*刷新窗口缓冲，显示 box
    */
    return local_win;
}

void WriteInWindow(WINDOW* window, int starty, int startx, std::string str)
{
    mvwprintw(window, ++starty, ++startx, str.c_str());
    wrefresh(window);
}

void Test0()
{
    initscr();
    cbreak();
    noecho();
    refresh();
    int width = 20;
    int height = 15;
    int swidth = 15;
    int sheight = 7;
    printw(FormatString("width[%d] height[%d] width[%d] height[%d]", COLS, LINES, width, height).c_str());
    refresh();
    // std::cout << FormatString("%s %d", "hahahah", 99) << std::endl;
    int starty = (LINES - height) / 2;
    int startx = (COLS - width) / 2;
    // create_newwin(height, width, startY, startX);
    WINDOW *mainWin = CreateNewWin(height, width, starty, startx);
    WINDOW *scoreBoard = CreateNewWin(sheight, swidth, starty, startx + width - 1);
    WriteInWindow(scoreBoard, 0, 0, FormatString("%s[%d]", "highest", 100));
    WriteInWindow(scoreBoard, 1, 0, FormatString("%s[%d]", "lowest", 60));
    getch();
    endwin();
}
};
